package com.slkj.config;

/**
 * @author: weilai
 * @date: 2020/2/10
 * @description:
 */

import com.slkj.dto.Result;
import com.slkj.dto.StatusCode;
import org.activiti.engine.ActivitiException;
import org.apache.shiro.authc.UnknownAccountException;
import org.csource.common.MyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;


@RestControllerAdvice
public class GlobalExceptionHandler {


    private Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);


    @ExceptionHandler(NullPointerException.class)
    public Result NullPointerExceptionHandler(NullPointerException e) {
        e.printStackTrace();
        return new Result(false, StatusCode.NULL, e.getMessage());
    }

    @ExceptionHandler(UnknownAccountException.class)
    public Result UnknownAccountExceptionHandler(NullPointerException e) {
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR, e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public Result RuntimeExceptionHandler(RuntimeException e) {
        e.printStackTrace();

        return new Result(false, StatusCode.ERROR, e.getMessage());
    }

    @ExceptionHandler(IOException.class)
    public Result IOExceptionHandler(IOException e) {
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR, e.getMessage());
    }

    @ExceptionHandler(MyException.class)
    public Result MyExceptionHandler(MyException e) {
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR, e.getMessage());
    }

    @ExceptionHandler(ActivitiException.class)
    public Result ActivitiExceptionHandler(ActivitiException e) {
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR, e.getMessage());
    }


}
